function loadGeneral(){
	var data = {func : "loadGeneralData"};
	var url = "/generlicLogicService";
	simpleservice(url,data,fillGeneral);
}

function fillGeneral(data){
	var objArray = new Array();
	objArray = JSON.parse(data);
	var checkLogOut = checkSessionAdmin(objArray);
	if(checkLogOut)
		return;
	$("#language").text(objArray['languageTitle']);
	$("#language").attr("refid",objArray['defaultLanguageString']);
	
	$("#currency").text(objArray['defaultCurrencyTitle']);
	$("#currency").attr("refid",objArray['defaultCurrencyString']);
	
	$("#financialyearfrom").text(displayfinancialyear(new Date(objArray['financialYearFrom'])));
	$("#financialyearfrom").attr("datetime",formatddmm(new Date(objArray['financialYearFrom'])));
	
	$("#financialyearto").text(displayfinancialyear(new Date(objArray['financialYearTo'])));
	$("#financialyearto").attr("datetime",formatddmm(new Date(objArray['financialYearTo'])));
	
	(objArray['currencyconvert'])? $("#currencyconvert").text("Automatic") : $("#currencyconvert").text("Manual");
	$("#currencyconvert").attr("refid",objArray['currencyconvert']);
	
	$("#currencymagin").text(objArray['currencyConversionMargin']);
	
	$("#decimalplaces").text(objArray['currencyDecimalPlaces']);
	$("#decimalplaces").attr("refid",objArray['currencyDecimalPlaces']);
	(objArray['taxBreakUp'])? $("#taxbreakup").text("Yes") : $("#taxbreakup").text("No");
	$("#taxbreakup").attr("refid",objArray['taxBreakUp']);
	(objArray['accountFolioOpeningDate'])? $("#foliodate").text("Yes") : $("#foliodate").text("No");
	$("#foliodate").attr("refid",objArray['accountFolioOpeningDate']);
	$("#dateformat").text(objArray['dateTimeFormat']);
	$("#dateformat").attr("refid",objArray['dateFormatString']);
	$("#gennerlic_timezone-dropdown").text(objArray['timeZone']);
	$("#gennerlic_timezone-dropdown").attr("refid",objArray['timeZone']);
	$("#gennerlic_timezone-dropdown").attr("GMT",objArray['GMT']);
	
	if(objArray['timeFormatShow24Hours']){
		$("#timeformat").text("24 Hours");
		$("#checkintime").text(displaytime24hour(new Date(objArray['checkInTime'])));
		$("#checkintime").attr("datetime",displaytime24hour(new Date(objArray['checkInTime'])).split(" ")[0]);
		$("#checkouttime").text(displaytime24hour(new Date(objArray['checkOutTime'])));
		$("#checkouttime").attr("datetime",displaytime24hour(new Date(objArray['checkOutTime'])).split(" ")[0]);
		$("#shownightaudit").text(displaytime24hour(objArray['nightAuditTime']));
		$("#shownightaudit").attr("datetime",displaytime24hour(objArray['nightAuditTime']).split(" ")[0]);
	}else{
		$("#timeformat").text("12 Hours");
		$("#checkintime").text(displaytime12hour(new Date(objArray['checkInTime'])));
		$("#checkintime").attr("datetime",displaytime24hour(new Date(objArray['checkInTime'])).split(" ")[0]);
		$("#checkouttime").text(displaytime12hour(new Date(objArray['checkOutTime'])));
		$("#checkouttime").attr("datetime",displaytime24hour(new Date(objArray['checkOutTime'])).split(" ")[0]);
		$("#shownightaudit").text(displaytime12hour(objArray['nightAuditTime']));
		$("#shownightaudit").attr("datetime",displaytime24hour(objArray['nightAuditTime']).split(" ")[0]);
	}
	$("#timeformat").attr("refid",objArray['timeFormatShow24Hours']);
	$("[name=symbol]").html(objArray['defaultCurrencySymbol']);
	$("#childold").text(objArray['assumechild']);
	$("#childold").attr("refid",objArray['assumechild']);
	$("#commission").text(objArray['agentcommission'].toFixed(2));
	$("#discount").text(objArray['coporatediscount'].toFixed(2));
	$("#nowdate").text(displaytimezone(new Date()));
	
	(objArray['incloudetax'])? $("#exclusivetax").text("Yes") : $("#exclusivetax").text("No");
	$("#exclusivetax").attr("refid",objArray['incloudetax']);
	$("#fee").text(objArray['feeforcancel'].toFixed(objArray['currencyDecimalPlaces']));
	$("#earlycheckin_timeamount").text(objArray['earlycheckintimeamount']);	
	$("#earlycheckin_timeamount").attr("value",objArray['earlycheckintimeamount']);
	(objArray['earlycheckintimeunit'])? $("#earlycheckin_timeunit").text(Days) : $("#earlycheckin_timeunit").text(Hours);
	$("#earlycheckin_timeunit").attr("value",objArray['earlycheckintimeunit']);
	$("#earlycheckin_chargeamount").text(objArray['earlycheckinchargeamount']);
	$("#earlycheckin_chargeamount").attr("value",objArray['earlycheckinchargeamount']);
	if(objArray['earlycheckinchargeunit'] == "0"){
		$("#earlycheckin_chargeunit").text(PercentOfBooking);
	}else if(objArray['earlycheckinchargeunit'] == "1"){
		$("#earlycheckin_chargeunit").html(objArray['defaultCurrencySymbol']);
	}else if(objArray['earlycheckinchargeunit'] == "2"){
		$("#earlycheckin_chargeunit").text(RoomNights);
	}
	$("#earlycheckin_chargeunit").attr("value",objArray['earlycheckinchargeunit']);
	
	$("#earlycheckout_timeamount").text(objArray['earlycheckouttimeamount']);
	$("#earlycheckout_timeamount").attr("value",objArray['earlycheckouttimeamount']);
	(objArray['earlycheckouttimeunit'])? $("#earlycheckout_timeunit").text(Days) : $("#earlycheckout_timeunit").text(Hours);
	$("#earlycheckout_timeunit").attr("value",objArray['earlycheckouttimeunit']);
	$("#earlycheckout_chargeamount").text(objArray['earlycheckoutchargeamount']);
	$("#earlycheckout_chargeamount").attr("value",objArray['earlycheckoutchargeamount']);
	if(objArray['earlycheckoutchargeunit'] == "0"){
		$("#earlycheckout_chargeunit").text(PercentOfBooking);
	}else if(objArray['earlycheckoutchargeunit'] == "1"){
		$("#earlycheckout_chargeunit").html(objArray['defaultCurrencySymbol']);
	}else if(objArray['earlycheckoutchargeunit'] == "2"){
		$("#earlycheckout_chargeunit").text(RoomNights);
	}
	$("#earlycheckout_chargeunit").attr("value",objArray['earlycheckoutchargeunit']);
	
	$("#latecheckout_timeamount").text(objArray['latecheckouttimeamount']);
	$("#latecheckout_timeamount").attr("value",objArray['latecheckouttimeamount']);
	(objArray['latecheckouttimeunit'])? $("#latecheckout_timeunit").text(Days) : $("#latecheckout_timeunit").text(Hours);
	$("#latecheckout_timeunit").attr("value",objArray['latecheckouttimeunit']);
	$("#latecheckout_chargeamount").text(objArray['latecheckoutchargeamount']);
	$("#latecheckout_chargeamount").attr("value",objArray['latecheckoutchargeamount']);
	if(objArray['latecheckoutchargeunit'] == "0"){
		$("#latecheckout_chargeunit").text(PercentOfBooking);
	}else if(objArray['latecheckoutchargeunit'] == "1"){
		$("#latecheckout_chargeunit").html(objArray['defaultCurrencySymbol']);
	}else if(objArray['latecheckoutchargeunit'] == "2"){
		$("#latecheckout_chargeunit").text(RoomNights);
	}
	$("#latecheckout_chargeunit").attr("value",objArray['latecheckoutchargeunit']);
	
	$("#occupied").text(objArray['occupiedCleaningStatusTitle']);
	$("#occupied").attr("refid",objArray['onNightAuditRollOverMarkOccupiedString']);
	
	$("#vacant").text(objArray['vacantCleaningStatusTitle']);
	$("#vacant").attr("refid",objArray['onNightAuditRollOverMarkVacantRoomString']);
	
	$("#checkedoutroom").text(objArray['checkoutCleaningStatusTitle']);
	$("#checkedoutroom").attr("refid",objArray['markCheckedOutRoomString']);
	
	$("#noshowtime").text(objArray['noshow_charge']+" ");
	$("#noshowtime").attr("value",objArray['noshow_charge']);
	
	(objArray['noshow_timeunit'])?$("#noshowtimeunit").text(Days+" ") : $("#noshowtimeunit").text(Hours1+" ");
	$("#noshowtimeunit").attr("value",objArray['noshow_timeunit']);
	
	(objArray['noshow_isExpectedArrival'])?$("#afterthis").text(" "+ExpectedArrivalTime) : $("#afterthis").text(" "+CheckInTime);
	$("#afterthis").attr("value",objArray['noshow_isExpectedArrival']);

	$("#setcounterlist").attr("posid",objArray["posid"]);
	$("#setcounterlist").attr("value",objArray["stringId"]);
	$("#counterlist").text(objArray["stringName"]);
	$("#defaultcounter").attr("refid",objArray["stringDefaultId"]);
	$("#defaultcounter").text(objArray["stringDefaultName"]);
}

function seted(data){
	$("#"+data.dom[0]['id']).attr("refid",data.select.find("option:selected").val());
	$("#"+data.dom[0]['id']).text(data.select.find("option:selected").text());
	if(data.dom[0]['id'] == "gennerlic_timezone-dropdown"){
		$("#"+data.dom[0]['id']).attr("GMT",data.select.find("option:selected").attr("attr"));
	}else if(data.dom[0]['id'] == "timeformat"){
		if(data.select.find("option:selected").val() == "true"){
			$("#checkintime").text(settime24($("#checkintime").attr("datetime")));
			$("#checkintime").attr("datetime",$("#checkintime").attr("datetime"));
			$("#checkouttime").text(settime24($("#checkouttime").attr("datetime")));
			$("#checkouttime").attr("datetime",$("#checkouttime").attr("datetime"));
			$("#shownightaudit").text(settime24($("#shownightaudit").attr("datetime")));
			$("#shownightaudit").attr("datetime",$("#shownightaudit").attr("datetime"));
		}else{
			$("#checkintime").text(settime12($("#checkintime").attr("datetime")));
			$("#checkintime").attr("datetime",$("#checkintime").attr("datetime"));
			$("#checkouttime").text(settime12($("#checkouttime").attr("datetime")));
			$("#checkouttime").attr("datetime",$("#checkouttime").attr("datetime"));
			$("#shownightaudit").text(settime12($("#shownightaudit").attr("datetime")));
			$("#shownightaudit").attr("datetime",$("#shownightaudit").attr("datetime"));
			
		}
	}
}

function showdropdownyesno(id){
	var showyes ={value:"true",show:"Yes"};
	var showno = {value:"false",show:"No"};
	var data = new Array(showyes,showno);
	fillSimpleDropdown($("#"+id),data,'value','show',seted,'false',"width:67px");
}

function showdropdowncurrencyconvert(){
	var auto ={value:"true",show:"Automatic"};
	var manual = {value:"false",show:"Manual"};
	var data = new Array(auto,manual);
	fillSimpleDropdown($("#currencyconvert"),data,'value','show',seted,'false',"width:85px");	
}

function settext(data){
	$("#"+data.dom[0]['id']).text(parseInt($(data.textbox[0]).val()).toFixed(2));
}

function showdropdownlanguage(){
		var idandcalback = new Array("language",seted);
		var url = "/generlicLogicService";
		var data = { func : "loadLanguage"
			}
		simpleserviceWithArgs(url,data,setdropdownlanguage,idandcalback);
}

function setdropdownlanguage(data,idandcalback){
	var objArray = new Array();
	objArray = JSON.parse(data);
	fillSimpleDropdown($("#"+idandcalback[0]),objArray,'id','title',idandcalback[1],'false',"width:67px");
}

function showdropdowncurrency(){
	var idandcalback = new Array("currency",seted);
	var url = "/generlicLogicService";
	var data = { func : "loadCurrency"
		}
	simpleserviceWithArgs(url,data,setdropdowncurrency,idandcalback);
}

function setdropdowncurrency(data,idandcalback){
	var objArray = new Array();
	objArray = JSON.parse(data);
	fillSimpleDropdown($("#"+idandcalback[0]),objArray,'id','title',idandcalback[1],'false',"width:120px");
}

function showdropdowndateformat(){
	var idandcalback = new Array("dateformat",seted);
	var url = "/generlicLogicService";
	var data = { func : "loadDateFormat"
		}
	simpleserviceWithArgs(url,data,setdropdowndateformat,idandcalback);
}

function setdropdowndateformat(data,idandcalback){
	var objArray = new Array();
	objArray = JSON.parse(data);
	fillSimpleDropdown($("#"+idandcalback[0]),objArray,'id','dateTimeFormat',idandcalback[1],'false',"width:150px");
}

function showdropdowncleaningstatus(id){
	var idandcalback = new Array(id,seted);
	var url = "/generlicLogicService";
	var data = { func : "loadCleaningStatus"
		}
	simpleserviceWithArgs(url,data,setdropdowncleaningstatus,idandcalback);
}

function setdropdowncleaningstatus(data,idandcalback){
	var objArray = new Array();
	objArray = JSON.parse(data);
	fillSimpleDropdown($("#"+idandcalback[0]),objArray,'id','title',idandcalback[1],'false',"width:150px");
}

function showdropdowntimeformat(id,callback){
	var showyes ={value:"true",show:"24 Hours"};
	var showno = {value:"false",show:"12 Hours"};
	var data = new Array(showyes,showno);
	fillSimpleDropdown($("#timeformat"),data,'value','show',seted,'false',"width:100px");
}

function showtimefrom(id){
	var oldDomSpan = $("#"+id).find("span")[0];
	var datetime = $(oldDomSpan).attr("datetime");
	var hours = datetime.split(":")[0];
	var minutes = datetime.split(":")[1];
	var ampm;
	if($("#timeformat").attr("refid") == "true"){
		var replacetext = selected24hour +" : " +selectedminute;
	}else{		
		if(hours >= 12) {
			ampm = 'PM'
			hours = hours-12;
		}else{
			ampm = 'AM';
		}
		var replacetext = "&nbsp;"+selected12hour+" : " +
				selectedminute+"&nbsp;" +selectedampm;
	}
	$("#"+id).html(replacetext);
	$("#hoursselected").val(appendzero(parseInt(hours)));
	$("#minuteselected").val(minutes);
	$("#ampmselected").val(ampm);
	$("#hoursselected").focus();
	var target;
	$(document).mousedown(function(e) {
		target = $(e.target);
    });
	
	$("#hoursselected").blur(function(e) {
		if(target.attr("id") != "minuteselected" && target.attr("id") != "hoursselected" 
			&& target.attr("id") != "ampmselected"){
			replacetime(id,oldDomSpan);
		}
		target = null;
	});
	
	$("#minuteselected").blur(function(e) {
		if(target.attr("id") != "minuteselected" && target.attr("id") != "hoursselected" 
			&& target.attr("id") != "ampmselected"){
			replacetime(id,oldDomSpan);
		}
		target = null;
	});
	
	$("#ampmselected").blur(function(e) {
		if(target.attr("id") != "minuteselected" && target.attr("id") != "hoursselected" 
			&& target.attr("id") != "ampmselected"){
			replacetime(id,oldDomSpan);
		}
		target = null;
	});
}

function replacetime(id,dom){
	var hours = $("#hoursselected").find(":selected").val();
	var minutes = $("#minuteselected").find(":selected").val()
	var ampm = $("#ampmselected").find(":selected").val();
	var spanId = dom.getAttribute("id");
	 
	var replacetext = "<span id=\""+spanId+"\"></span>&nbsp;&nbsp;&nbsp;" +
			"<span class=\"link\" onClick=\"showtimefrom('"+id+"')\">" +
			ClickToChange +
			"</span>";
	$("#"+id).html(replacetext);
	
	if($("#timeformat").attr("refid") == "true"){
		$("#"+dom.getAttribute("id")).text(hours + ":" + minutes + " Hours");
		$("#"+dom.getAttribute("id")).attr("datetime",hours + ":" + minutes);
	}else{
		if(ampm == "PM"){
			hours = parseInt(hours) + 12;
		}
		$("#"+dom.getAttribute("id")).attr("datetime",hours + ":" + minutes);
		
		if(hours >= 12){
			hours = parseInt(hours) - 12;
		}
		$("#"+dom.getAttribute("id")).text(hours + ":" + minutes + " " +ampm);	
	}
}

function showfinancialyearform(){
	var datefrom = $("#financialyearfrom").attr("datetime");
	var dayfrom = datefrom.split("/")[0];
	var monthfrom = datefrom.split("/")[1];
	var dateto = $("#financialyearto").attr("datetime");
	var dayto = dateto.split("/")[0];
	var monthto = dateto.split("/")[1];
	var monthoption = 	"<option value=\"0\">"+FullMonth[0]+"</option>" +
	"<option value=\"1\">"+FullMonth[1]+"</option>" +
	"<option value=\"2\">"+FullMonth[2]+"</option>" +
	"<option value=\"3\">"+FullMonth[3]+"</option>" +
	"<option value=\"4\">"+FullMonth[4]+"</option>" +
	"<option value=\"5\">"+FullMonth[5]+"</option>" +
	"<option value=\"6\">"+FullMonth[6]+"</option>" +
	"<option value=\"7\">"+FullMonth[7]+"</option>" +
	"<option value=\"8\">"+FullMonth[8]+"</option>" +
	"<option value=\"9\">"+FullMonth[9]+"</option>" +
	"<option value=\"10\">"+FullMonth[10]+"</option>" +
	"<option value=\"11\">"+FullMonth[11]+"</option>";
	var selectmonthfrom = "<select id=\"monthfrom\" OnChange=\"checkoptiondate(id)\">" +
							monthoption+"</select>";
	var selectmonthto = "<select id=\"monthto\" OnChange=\"checkoptiondate(id)\">" +
							monthoption+"</select>";
	var selectdayfrom = "<select id=\"dayfrom\"></select>";
	var selectdayto = "<select id=\"dayto\"></select>";
	var replacetext = selectdayfrom +" "+selectmonthfrom + " " + TextTo + 
						" " +selectdayto+ " " +selectmonthto;
	$("#financialform").html(replacetext);
	$("#monthfrom").val(monthfrom);
	$("#monthto").val(monthto);
	generaldayoption('dayfrom');
	generaldayoption('dayto');
	$("#dayfrom").val(dayfrom);
	$("#dayto").val(dayto);
	$("#dayfrom").focus();
	var target;
	$(document).mousedown(function(e) {
		target = $(e.target);
    });
	$("#dayfrom").blur(function(e) {
		if(target.attr("id") != "dayfrom" && target.attr("id") != "monthfrom" 
			&& target.attr("id") != "dayto" && target.attr("id") != "monthto"){
			replacefinancialyear();
		}
		target = null;
	});
	$("#monthfrom").blur(function(e) {
		if(target.attr("id") != "dayfrom" && target.attr("id") != "monthfrom" 
			&& target.attr("id") != "dayto" && target.attr("id") != "monthto"){
			replacefinancialyear();
		}
		target = null;
	});
	$("#dayto").blur(function(e) {
		if(target.attr("id") != "dayfrom" && target.attr("id") != "monthfrom" 
			&& target.attr("id") != "dayto" && target.attr("id") != "monthto"){
			replacefinancialyear();
		}
		target = null;
	});
	$("#monthto").blur(function(e) {
		if(target.attr("id") != "dayfrom" && target.attr("id") != "monthfrom" 
			&& target.attr("id") != "dayto" && target.attr("id") != "monthto"){
			replacefinancialyear();
		}
		target = null;
	});
}

function replacefinancialyear(){
	var dayfrom = $("#dayfrom").val();
	var dayto = $("#dayto").val();
	var monthfrom = $("#monthfrom").val();
	var monthto = $("#monthto").val();
	var replacetext = "<span id=\"financialyearfrom\"></span>&nbsp;"+TextTo+
	"&nbsp;<span id=\"financialyearto\"></span>&nbsp;&nbsp;&nbsp;<span class=\"link\" " +
	"onClick=\"showfinancialyearform()\">"+ClickToChange+"</span>";
	$("#financialform").html(replacetext);
	$("#financialyearfrom").text(dayfrom + " "+FullMonth[monthfrom]);
	$("#financialyearfrom").attr("datetime",dayfrom+"/"+monthfrom);
	$("#financialyearto").text(dayto + " "+FullMonth[monthto]);
	$("#financialyearto").attr("datetime",dayto+"/"+monthto);
}

function generaldayoption(id){
	if(id == "dayfrom"){
		var month = $("#monthfrom").val();
	}else if(id == "dayto"){
		var month = $("#monthto").val();
	}	
	var dayamount = daysinmonth(month);
	for(var i = 1;i <= dayamount ;i++){
		$("#"+id).append($("<option>").val((i)).html((i)));
	}
}

function checkoptiondate(id){
	var monthselect = $("#"+id).val();
	if(id == "monthfrom"){
		var dayselectid = "dayfrom";
	}else if(id == "monthto"){
		var dayselectid = "dayto";
	}
	var dayselect = $("#"+dayselectid).val(); 
	var daynowsize = $("#"+dayselectid).size();
	var daynewsize = daysinmonth(monthselect);
	if(daynowsize != daynewsize){
		$("#"+dayselectid+" option").remove();
		generaldayoption(dayselectid);
	}
	if(dayselect > daynewsize){
		$("#"+dayselectid).val(daynewsize);
	}else{
		$("#"+dayselectid).val(dayselect);
	}
}

function daysinmonth(num){
	if(parseInt(num) == 0 || parseInt(num) == 2 || parseInt(num) == 4 || parseInt(num) == 6 ||
			parseInt(num) == 7 || parseInt(num) == 9 || parseInt(num) == 11 ){
		return 31;
	}else if(parseInt(num) == 3 || parseInt(num) == 5 || parseInt(num) == 8 || 
			parseInt(num) == 10){
		return 30;
	}else if(parseInt(num) == 1 ){
		return 28;
	}
}

function noshowpolicyform(){
	var noshowtime = $("#noshowtime").attr("value");
	var noshowtimeunit = $("#noshowtimeunit").attr("value");
	var afterthis = $("#afterthis").attr("value");
	var replacetext = "<table style=\"width:75%;padding-left:20%\">" +
			"<tr><td style=\"text-align:right\">"+ChargeNoShow+"</td><td>" +
					"<input id=\"chargeamount\" type=\"text\" size=\"10\"/>" +
				"</td><td style=\"text-align:left\">" +
					"<input type=\"radio\" name=\"chargeunit\" value=\"true\" id=\"day\" />" + Days+
						"<br />" +
					"<input type=\"radio\" name=\"chargeunit\" value=\"false\" id=\"hour\" />" + Hours1+
						"<br />" +
				"</td><td style=\"text-align:left\">"+After+"</td><td style=\"text-align:left\">" +
					"<input type=\"radio\" name=\"afterthis\" value=\"true\" " +
					"id=\"afterexpectedarrivaltime\" />"+ExpectedArrivalTime+"<br />" +
					"<input type=\"radio\" name=\"afterthis\" value=\"false\" " +
					"id=\"aftercheckintime\" />"+CheckInTime+"<br />" +
				"</td></tr></table>";
	$("#noshowpolicy").html(replacetext);
	$("#chargeamount").focus();
	$("#chargeamount").val(noshowtime);
	(noshowtimeunit == "true")? $("#day").attr("checked",true) : $("#hour").attr("checked",true); 
	(afterthis == "true")? $("#afterexpectedarrivaltime").attr("checked",true) : $("#aftercheckintime").attr("checked",true);
	
	var target;
	$(document).mousedown(function(e) {
		target = $(e.target);
		
    });
	
	$("#noshowpolicy").blur(function(e) {
		if(target.attr("id") != "chargeamount" && target.attr("id") != "day" && target.attr("id") != "hour"
			&& target.attr("id") != "afterexpectedarrivaltime" && target.attr("id") != "aftercheckintime"){
			replacenoshow();
		}
		target = null;
	});
	$("#chargeamount").blur(function(e) {
		debugger;
		if(target.attr("id") != "chargeamount" && target.attr("id") != "day" && target.attr("id") != "hour"
			&& target.attr("id") != "afterexpectedarrivaltime" && target.attr("id") != "aftercheckintime"){
			replacenoshow();
		}
		target = null;
	});
	$("#day").blur(function(e) {
		if(target.attr("id") != "chargeamount" && target.attr("id") != "day" && target.attr("id") != "hour"
			&& target.attr("id") != "afterexpectedarrivaltime" && target.attr("id") != "aftercheckintime"){
			replacenoshow();
		}
		target = null;
	});
	$("#hour").blur(function(e) {
		if(target.attr("id") != "chargeamount" && target.attr("id") != "day" && target.attr("id") != "hour"
			&& target.attr("id") != "afterexpectedarrivaltime" && target.attr("id") != "aftercheckintime"){
			replacenoshow();
		}
		target = null;
	});
	$("#afterexpectedarrivaltime").blur(function(e) {
		if(target.attr("id") != "chargeamount" && target.attr("id") != "day" && target.attr("id") != "hour"
			&& target.attr("id") != "afterexpectedarrivaltime" && target.attr("id") != "aftercheckintime"){
			replacenoshow();
		}
		target = null;
	});
	$("#aftercheckintime").blur(function(e) {
		if(target.attr("id") != "chargeamount" && target.attr("id") != "day" && target.attr("id") != "hour"
			&& target.attr("id") != "afterexpectedarrivaltime" && target.attr("id") != "aftercheckintime"){
			replacenoshow();
		}
		target = null;
	});
}

function replacenoshow(){
	var chargeamount = $("#chargeamount").val();
	var chargeunit = $("[name=chargeunit]:checked").val();
	var chargeunittext;
	var afterthis = $("[name=afterthis]:checked").val();
	var afterthistext;
	($("[name=chargeunit]:checked").val() == "true")? chargeunittext = Days : chargeunittext = Hours1;
	($("[name=afterthis]:checked").val() == "true")? afterthistext = ExpectedArrivalTime : afterthistext = CheckInTime;
	var replacetext = "<span>"+ChargeNoShow+"</span>" +
			"<span id=\"noshowtime\" value=\""+chargeamount+"\">&nbsp;"+chargeamount+"&nbsp;</span>" +
			"<span id=\"noshowtimeunit\" value=\""+chargeunit+"\">"+chargeunittext+" </span>" +After+
			"<span id=\"afterthis\" value=\""+afterthis+"\"> "+afterthistext+"</span> " +
			"&nbsp;&nbsp;&nbsp;" +
			"<span class=\"link\" onclick=\"noshowpolicyform()\">"+ClickToChange+"</span>";
	$("#noshowpolicy").html(replacetext);
}

function earlypolicyform(id){
	var text1 = $("#"+id+"_1").text();
	var text2 = $("#"+id+"_2").text();
	var timeunit = $("#"+id+"_timeunit").attr("value");
	var timeamount = $("#"+id+"_timeamount").attr("value");
	var chargeamount = $("#"+id+"_chargeamount").attr("value");
	var chargeunit = $("#"+id+"_chargeunit").attr("value");
	var replacetext = "<table style=\"width:100%;padding-left:50px\"><tr>" +
				"<td>"+text1+"</td>" +
				"<td><input id=\"timeamount\" type=\"text\" size=\"5\" /></td>" +
				"<td>" +
					"<input type=\"radio\" name=\"timeunit\" value=\"true\" id=\"timeunit_0\" />" +Days+
					"<br />" +
					"<input type=\"radio\" name=\"timeunit\" value=\"false\" id=\"timeunit_1\" />" +Hours+
					"<br />" +
				"</td>" +
				"<td>"+text2+"</td>" +
				"<td><input id=\"chargeamount\" type=\"text\" size=\"5\" /></td>" +
				"<td>" +
				"<input type=\"radio\" name=\"chargeunit\" value=\"0\" id=\"chargeunit_0\" />"+PercentOfBooking+"<br />" +
				"<input type=\"radio\" name=\"chargeunit\" value=\"1\" id=\"chargeunit_1\" />"+xSymbol+"<br />" +
				"<input type=\"radio\" name=\"chargeunit\" value=\"2\" id=\"chargeunit_2\" />"+RoomNights+"<br />" +
				"</td></tr></table>";
	$("#"+id).html(replacetext);
	$("#timeamount").val(timeamount);
	if(timeunit == "true"){
		$("#timeunit_0").attr("checked",true);
	}else{
		$("#timeunit_1").attr("checked",true)
	}
	$("#chargeamount").val(chargeamount);
	$("#chargeunit_"+chargeunit).attr("checked",true);
	
	$("#timeamount").focus();
	
	var target;
	$(document).mousedown(function(e) {
		target = $(e.target);
    });
	$("#timeamount").blur(function(e) {
		if(target.attr("id") != "timeamount" && target.attr("id") != "timeunit_0" 
			&& target.attr("id") != "timeunit_1" && target.attr("id") != "chargeamount"
			&& target.attr("id") != "chargeunit_0" && target.attr("id") != "chargeunit_1"
			&& target.attr("id") != "chargeunit_2"){
			replaceearlypolicy(id,text1,text2);
		}
		target = null;
	});
	$("#timeunit_0").blur(function(e) {
		if(target.attr("id") != "timeamount" && target.attr("id") != "timeunit_0" 
			&& target.attr("id") != "timeunit_1" && target.attr("id") != "chargeamount"
				&& target.attr("id") != "chargeunit_0" && target.attr("id") != "chargeunit_1"
				&& target.attr("id") != "chargeunit_2"){
			replaceearlypolicy(id,text1,text2);
		}
		target = null;
	});
	$("#timeunit_1").blur(function(e) {
		if(target.attr("id") != "timeamount" && target.attr("id") != "timeunit_0" 
			&& target.attr("id") != "timeunit_1" && target.attr("id") != "chargeamount"
				&& target.attr("id") != "chargeunit_0" && target.attr("id") != "chargeunit_1"
				&& target.attr("id") != "chargeunit_2"){
			replaceearlypolicy(id,text1,text2);
		}
		target = null;
	});
	$("#chargeamount").blur(function(e) {
		if(target.attr("id") != "timeamount" && target.attr("id") != "timeunit_0" 
			&& target.attr("id") != "timeunit_1" && target.attr("id") != "chargeamount"
				&& target.attr("id") != "chargeunit_0" && target.attr("id") != "chargeunit_1"
				&& target.attr("id") != "chargeunit_2"){
			replaceearlypolicy(id,text1,text2);
		}
		target = null;
	});
	$("#chargeunit_0").blur(function(e) {
		if(target.attr("id") != "timeamount" && target.attr("id") != "timeunit_0" 
			&& target.attr("id") != "timeunit_1" && target.attr("id") != "chargeamount"
				&& target.attr("id") != "chargeunit_0" && target.attr("id") != "chargeunit_1"
				&& target.attr("id") != "chargeunit_2"){
			replaceearlypolicy(id,text1,text2);
		}
		target = null;
	});
	$("#chargeunit_1").blur(function(e) {
		if(target.attr("id") != "timeamount" && target.attr("id") != "timeunit_0" 
			&& target.attr("id") != "timeunit_1" && target.attr("id") != "chargeamount"
				&& target.attr("id") != "chargeunit_0" && target.attr("id") != "chargeunit_1"
				&& target.attr("id") != "chargeunit_2"){
			replaceearlypolicy(id,text1,text2);
		}
		target = null;
	});
	$("#chargeunit_2").blur(function(e) {
		if(target.attr("id") != "timeamount" && target.attr("id") != "timeunit_0" 
			&& target.attr("id") != "timeunit_1" && target.attr("id") != "chargeamount"
				&& target.attr("id") != "chargeunit_0" && target.attr("id") != "chargeunit_1"
				&& target.attr("id") != "chargeunit_2"){
			replaceearlypolicy(id,text1,text2);
		}
		target = null;
	});
}

function replaceearlypolicy(id,text1,text2){
	var timeamount = $("#timeamount").val();
	var timeunit = $("[name=timeunit]:checked").val();
	var timeunittext;
	if(timeunit == "true"){
		timeunittext = Days;
	}else{
		timeunittext = Hours;
	}
	
	var chargeamount = $("#chargeamount").val();
	var chargeunit = $("[name=chargeunit]:checked").val();
	var chargeunittext;
	if(chargeunit == "0"){
		chargeunittext = PercentOfBooking;
	}else if(chargeunit == "1"){
		chargeunittext = xSymbol;
	}else if(chargeunit == "2"){
		chargeunittext = RoomNights;
	}
	var replacetext = "<div id=\""+id+"\">" +
			"<span id=\""+id+"_1\">"+text1+"</span>&nbsp;" +
			"<span id=\""+id+"_timeamount\" value=\""+timeamount+"\">"+timeamount+"</span>&nbsp;" +
			"<span id=\""+id+"_timeunit\" value=\""+timeunit+"\">"+timeunittext+"</span>" +
			"<span id=\""+id+"_2\">"+text2+"</span>&nbsp;" +
			"<span id=\""+id+"_chargeamount\" value=\""+chargeamount+"\">"+chargeamount+"</span>&nbsp;" +
			"<span id=\""+id+"_chargeunit\" value=\""+chargeunit+"\">"+chargeunittext+"</span>&nbsp;" +
			"<span class=\"link\" onclick=\"earlypolicyform('"+id+"')\">"+ClickToChange+"</span>" +
			"&nbsp;</div>";
	$("#"+id).html(replacetext);
}

function savechange(){
	var includetax = $("#exclusivetax").attr("refid");
	var taxbreakup = $("#taxbreakup").attr("refid");
	var foliodate = $("#foliodate").attr("refid");
	var currencyconvert = $("#currencyconvert").attr("refid");
	var decimalplaces = $("#decimalplaces").attr("refid");
	var childold = $("#childold").attr("refid");
	var commission = $("#commission").text();
	var discount = $("#discount").text();
	var currencymagin = $("#currencymagin").text();
	var language = $("#language").attr("refid");
	var currency = $("#currency").attr("refid");
	var dateformat = $("#dateformat").attr("refid");
	var timezone = $("#gennerlic_timezone-dropdown").attr("refid");
	var GMT = $("#gennerlic_timezone-dropdown").attr("gmt");
	var occupied = $("#occupied").attr("refid");
	var vacant = $("#vacant").attr("refid");
	var checkedoutroom = $("#checkedoutroom").attr("refid");
	var timeformat = $("#timeformat").attr("refid");
	var checkintime = $("#checkintime").attr("datetime");
	var checkouttime = $("#checkouttime").attr("datetime");
	var nightaudittime = $("#shownightaudit").attr("datetime");
	var financialyearfrom = $("#financialyearfrom").attr("datetime");
	var financialyearto = $("#financialyearto").attr("datetime");
	var earlycheckintimeamount = $("#earlycheckin_timeamount").attr("value");
	var earlycheckintimeunit = $("#earlycheckin_timeunit").attr("value");
	var earlycheckinchargeamount = $("#earlycheckin_chargeamount").attr("value");
	var earlycheckinchargeunit = $("#earlycheckin_chargeunit").attr("value");
	var earlycheckouttimeamount = $("#earlycheckout_timeamount").attr("value");
	var earlycheckouttimeunit = $("#earlycheckout_timeunit").attr("value");
	var earlycheckoutchargeamount = $("#earlycheckout_chargeamount").attr("value");
	var earlycheckoutchargeunit = $("#earlycheckout_chargeunit").attr("value");
	var latecheckouttimeamount = $("#latecheckout_timeamount").attr("value");
	var latecheckouttimeunit = $("#latecheckout_timeunit").attr("value");
	var latecheckoutchargeamount = $("#latecheckout_chargeamount").attr("value");
	var latecheckoutchargeunit = $("#latecheckout_chargeunit").attr("value");
	
	var noshowtime = $("#noshowtime").attr("value");
	var noshowtimeunit = $("#noshowtimeunit").attr("value");
	var afterthis = $("#afterthis").attr("value");
	
	var posid = $("#setcounterlist").attr("posid");
	var counterid = $("#setcounterlist").attr("value");
	var defaultcounter = $("#defaultcounter").attr("refid");
	if(defaultcounter == "-"){
		simpleDialog("Please Select Default Counter");
		return false;
	}
	var data = {func : "savechange",
			includetax : includetax,
			taxbreakup : taxbreakup,
			foliodate : foliodate,
			currencyconvert : currencyconvert,
			decimalplaces : decimalplaces,
			childold : childold,
			commission : commission,
			discount : discount,
			currencymagin : currencymagin,
			language : language,
			currency : currency,
			dateformat : dateformat,
			timezone : timezone,
			GMT : GMT,
			occupied : occupied,
			vacant : vacant,
			checkedoutroom : checkedoutroom,
			timeformat : timeformat,
			checkintime : checkintime,
			checkouttime : checkouttime,
			nightaudittime : nightaudittime,
			financialyearfrom : financialyearfrom,
			financialyearto : financialyearto,
			earlycheckintimeamount :earlycheckintimeamount,
			earlycheckintimeunit : earlycheckintimeunit,
			earlycheckinchargeamount : earlycheckinchargeamount,
			earlycheckinchargeunit : earlycheckinchargeunit,
			earlycheckouttimeamount : earlycheckouttimeamount,
			earlycheckouttimeunit : earlycheckouttimeunit,
			earlycheckoutchargeamount : earlycheckoutchargeamount,
			earlycheckoutchargeunit : earlycheckoutchargeunit,
			latecheckouttimeamount : latecheckouttimeamount,
			latecheckouttimeunit : latecheckouttimeunit,
			latecheckoutchargeamount : latecheckoutchargeamount,
			latecheckoutchargeunit : latecheckoutchargeunit,
			noshowtime : noshowtime,
			noshowtimeunit : noshowtimeunit,
			afterthis : afterthis,
			posid : posid,
			counterid : counterid,
			defaultcounter : defaultcounter
	};
	var url = "/generlicLogicService";
	simpleservice(url,data,refresh);
}

function refresh(){
	document.location.href ="/adminconsole/General/defaultssettings.jsp";
}

function displaytime12hour(datetime){
	var hour = new Date(datetime).getHours();
	var suffex = (hour >= 12)? 'PM' : 'AM';
	hour = (hour > 12)? hour -12 : hour;
	hour = (hour == '00')? 12 : hour;
	var min = new Date(datetime).getMinutes();
	return appendzero(hour)+":"+appendzero(min)+" "+suffex;
}

function displaytime24hour(datetime){
	var hour = new Date(datetime).getHours();
	var min = new Date(datetime).getMinutes();
	return appendzero(hour)+":"+appendzero(min)+" Hours";
}

function settime24(time){	
	var hours = time.split(":")[0];
	var minutes = time.split(":")[1];
	return appendzero(parseInt(hours)) + ":" + appendzero(parseInt(minutes)) + " Hours";
}

function settime12(time){
	var ampm = "AM";
	var hours = time.split(":")[0];
	if(parseInt(hours) >= 12){
		hours = parseInt(hours) - 12;
		ampm = "PM";
	}
	var minutes = time.split(":")[1];
	return appendzero(parseInt(hours)) + ":" + appendzero(parseInt(minutes)) + " " + ampm;
}

function appendzero(min){
	if(min >=0 && min <10){
		return "0"+min;
	}else{
		return min;
	}
}

function displayfinancialyear(date){
	return date.getDate()+" "+FullMonth[date.getMonth()];
}

function formatddmm(date){
	return date.getDate()+"/"+date.getMonth();
}

function displaytimezone(date){
	return ShortDay[date.getDay()] +" "+ date.getDate()+ " " + FullMonth[date.getMonth()] + " " + date.getFullYear() 
	+ " " + date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
}

function SetDefaultCounter(){
	debugger;
	var idArray = $("#setcounterlist").attr("value").split(",");
	var textArray = $("#counterlist").text().split(",");
	var defaultcounter = $("#setdefaultcounter").attr("refid");
	var data = new Array();
	for(var i=0;i<idArray.length;i++){
		var showyes ={id:idArray[i],text:textArray[i]};
		data.push(showyes);
	}
	fillSimpleDropdown($("#defaultcounter"),data,'id','text',seted,defaultcounter,"width:100px");
}

function SetCounterList(){
	var id = $("#setcounterlist").attr("value").split(",");
	var url = "/POSService";
	var data = { func : "getFront"
		}
	simpleserviceWithArgs(url,data,replaceSettingFront,id);
}

function replaceSettingFront(data,id){
	var objArray = new Array();
	objArray = JSON.parse(data);
	$("#setcounterlist").html("<table id=\"countertable\" style=\"width:80%\"><tr><td colspan=\"2\">Counter List</td></tr></table>");
	var text = "<tr>";
	var sumtext = "";
	for(var i=0;i<objArray.length;i++){
		if(i%4 !=0 && i != objArray.length-1){
			text += "<td style=\"width:3%\"><input type=\"checkbox\" name=\"counter\" title=\""+objArray[i]['title']+"\" value=\""+objArray[i]['id']+"\" ></td>"+
			"<td>"+objArray[i]['title']+"</td>";
		}else if(i%4 == 0 && i != objArray.length-1){
			text += "</tr><tr><td style=\"width:3%\"><input type=\"checkbox\" name=\"counter\" title=\""+objArray[i]['title']+"\" value=\""+objArray[i]['id']+"\"></td>"+
			"<td>"+objArray[i]['title']+"</td>";
		}else if(i%4 != 0 && i == objArray.length-1){
			text += "<td style=\"width:3%\"><input type=\"checkbox\" name=\"counter\" title=\""+objArray[i]['title']+"\" value=\""+objArray[i]['id']+"\"></td>"+
			"<td>"+objArray[i]['title']+"</td></tr>";
		}else if(i%4 == 0 && i == objArray.length-1){
			text += "</tr><tr><td style=\"width:3%\"><input type=\"checkbox\" name=\"counter\" title=\""+objArray[i]['title']+"\" value=\""+objArray[i]['id']+"\"></td>"+
			"<td>"+objArray[i]['title']+"</td></tr>";
		}
	}
	sumtext += text;
	$("#countertable").append(sumtext);
	for(var i=0;i<id.length;i++){
		for(var x=0;x<$("#countertable [type=checkbox]").size();x++){
			if($("#countertable [type=checkbox]")[x].value == id[i]){
				$($("#countertable [type=checkbox]")[x]).attr("checked",true);
				break;
			}
		}
	}
	
	var target;
	$(document).mousedown(function(e) {
		target = $(e.target);
    });
	$("[name=counter]").blur(function(e) {
		if(target.attr("name") != "counter"){
			replaceSetFront();
		}
		target = null;
	});
}

function replaceSetFront(){
	var idString = "";
	var idName = "";
	for(var i=0;i<$("[name=counter]").size();i++){
		if($($("[name=counter]")[i]).is(":checked")){
			idString += $($("[name=counter]")[i]).val() + ",";
			idName += $($("[name=counter]")[i]).attr("title") + ",";
		}else{
			if($($("[name=counter]")[i]).val() == $("#defaultcounter").attr("refid")){
				$("#defaultcounter").text("-");
				$("#defaultcounter").attr("refid","-");
			}
		}
	}
	idString = idString.substring(0,idString.length - 1);
	idName = idName.substring(0,idName.length - 1);
	var replacetext = xCounterList+" : <span id=\"counterlist\">"+idName+"</span> <span class=\"link\" " +
					"onClick=\"SetCounterList()\">"+ClickToChange+"</span>";
$("#setcounterlist").html(replacetext);
$("#setcounterlist").attr("value",idString);
}